package com.example.mydemo.mydemo3;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;

//<bean id="service" class="com.example.mydemo.mydemo2.Service"></bean>

@org.springframework.stereotype.Service
@Scope("prototype")        //bean的作用范围
public class Service implements ServiceImplement {
    //@Value("XiaoYou")
   @Value("${jdbc.driver}")  //从spring容器中找对应的key
    private String driver;
    //@Autowired              //<property name="dao" ref="dao"></property>,按照类型从spring容器中匹配
    //@Qualifier("dao")        //是按照id值从容器中进行匹配，但是要与@Autowired配合使用
    @Resource(name="dao")           //相当于@Autowired + @Qualifier name的值是id值
    private Dao dao;
    public void go(){
        System.out.println(driver);
        dao.go();
    }

    @PostConstruct
    public void postConstruct(){
        System.out.println("初始化方法已经创建");
    }

    @PreDestroy
    public void preDestroy(){
        System.out.println("销毁方法已经创建");
    }


}
